package com.imdroid.logic;

import java.util.Calendar;
import java.util.Collection;
import java.util.Date;

import net.orange.architecture.db.Condition;
import net.orange.architecture.db.Conditions;
import net.orange.architecture.db.Operator;
import net.orange.architecture.db.Order;
import net.orange.architecture.db.Orders;
import net.orange.architecture.process.BaseProcess;

/**
 * The process of device location
 * 
 */
public class LocationProcess extends BaseProcess implements ILocationProcess {
	/*
	 * (non-Javadoc)
	 * 
	 * @see com.imdroid.logic.IDeviceProcess#getPath(long, int)
	 */
	public Collection getPath(long userPk, int dayBefore) throws Exception {
		Calendar cal = Calendar.getInstance();
		cal.add(Calendar.DATE,   -1 * dayBefore);
		Date date = new Date(cal.getTimeInMillis());
		Conditions cnds = new Conditions();
		cnds.add(new Condition("device.user_id", userPk));
		cnds.add(new Condition("pos_date", new Operator(Operator.LARGER_THAN),
				date));

		Orders orders = new Orders();
		orders.add(new Order("pk", Order.DESC));
		return dao.list(cnds, orders);
	}
}
